package enrique.kurso.lecionoj;

import java.util.ArrayList;
import java.util.List;

import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import enrique.kurso.Main;
import enrique.kurso.R;


public class Leciono01 extends ListActivity {
	 private ListAdapter m_adapter;
	    
	    @Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.list);

	        List<String> options=new ArrayList<String>();
	        options.add(getResources().getString(R.string.alfabeto));
	        options.add(getResources().getString(R.string.comprensionAuditiva));
	        options.add(getResources().getString(R.string.pronombresPersonales));
	        options.add(getResources().getString(R.string.verbos));
	        options.add(getResources().getString(R.string.glosario));
	        options.add(getResources().getString(R.string.plural));
	        options.add(getResources().getString(R.string.pronombresPosesivos));
	        options.add(getResources().getString(R.string.articulo));
	        options.add(getResources().getString(R.string.frases));
	        options.add(getResources().getString(R.string.vortoLudo));
	        options.add(getResources().getString(R.string.traduzcaEsperanto));
	        
	        this.m_adapter = new ListAdapter(this, R.layout.leciono,options);
	        setListAdapter(this.m_adapter);
	    }

	   protected void onResume() {
		   super.onResume();
		   ((ListAdapter) this.getListAdapter()).notifyDataSetChanged();
	    }
	 
	    protected void onListItemClick(ListView l, View v, int position, long id) {
	    	Intent intent = null;
	    	switch (position) {
			case 0:
				intent=new Intent(this, Leciono0101.class);
				break;
			case 1:
				intent=new Intent(this, Leciono0102.class);
				break;
			case 2:
				intent=new Intent(this, Leciono0103.class);
				break;
			case 3:
				intent=new Intent(this, Leciono0104.class);
				break;
			case 4:
				intent=new Intent(this, VortoLudo.class);
				intent.putExtra("fichero", "vortoludo01011.txt");
				break;
			case 5:
				intent=new Intent(this, Leciono0106.class);
				break;
			default:
				break;
			}
	    	
	        intent.putExtra("exerciseType", position+1);
	        startActivity(intent);
	    }
	    
	    private class ListAdapter extends ArrayAdapter<String> {

	        private List<String> items;
	        private Context context;

	        public ListAdapter(Context context, int textViewResourceId, List<String> items) {
	                super(context, textViewResourceId, items);
	                this.items = items;
	                this.context = context;
	        }

	        public void setItems(List<String> items) {
	                this.items = items;
	                
	        }
	        
	        @Override
	        public View getView(int position, View convertView, ViewGroup parent) {
	                View v = convertView;
	                if (v == null) {
	                    LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	                    v = vi.inflate(R.layout.leciono, null);
	                }
	                String titulo = items.get(position);
	                if (titulo!=null) {
	                        TextView tt = (TextView) v.findViewById(R.id.toptext);
	                        if (tt != null) {
	                              tt.setText(titulo);
	                        }

	                     
	                    
	                        ImageView exercise = (ImageView) v.findViewById(R.id.exerciseDone);
	                }
	                return v;
	        }
	}
}
